<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <h3>模板图片管理</h3>
            <ul class="tab-base">
                <li><a href="JavaScript:void(0);" class="current"><span>图片管理</span></a></li>
            </ul>
        </div>
    </div>
    <div class="fixed-empty"></div>

    <div style="font-weight: bold;font-size: 15px;">
        备注：如图片上传失败，请使用chrome、firefox、opera以及各种双核浏览器的极速模式
    </div>
    <hr>

    <script src="/data/resource/js/ko.js"></script>
    <script src="/data/resource/layer_old/layer.js"></script>
    <script src="/data/resource/js/model_edit.js"></script>
    <script src="/data/resource/js/avalon.js"></script>
    <script src="/data/resource/js/common_select.js"></script>
    <script src="/data/resource/js/jquery.ajaxContent.pack.js"></script>
    <script>
        $.fn.extend({
            children : function () {
                var ret = [];
                this.each(function () {
                    for(var i = 0; i < this.childNodes.length; i++) {
                        ret.push(this.childNodes[i]);
                    }
                })
                return $(ret);
            }
        })
    </script>
    <?php
    $config = Model('setting')->getListSetting();
    $base_path = dirname(BASE_PATH) . '/shop/templates/' . $config['template_name'] . '/';
    $template = dirname(BASE_PATH) . '/shop/templates/' . $config['template_name'] . '/images.json';
    if (file_exists($template)) {
        $images_config = json_decode(file_get_contents($template), true);
    } else {
        $images_config = array();
    }
    $model_class = Model('goods_class');
    $goods_class = $model_class->getTreeClassList(1);//第一级商品分类
    ?>

    <style>
        table td img {
            cursor: pointer;
        }

    </style>
    <script>
        function imgerror(t) {
            t.src = '/data/upload/shop/common/default_goods_image.gif'
        }
        window.template_path = '<?php echo '/shop/templates/'. $config['template_name']. '/'; ?>';
        window.template_path = '';
    </script>
    <table class="table tb-type2">
        <?php
            foreach ($images_config as $key => $item) {
        ?>
            <tr class="name">
                <td colspan="100" style="font-weight: bold;">
                    <?php echo $key; ?> ：
                </td>
            </tr>
            <tr class="<?php if (is_array($item)) echo 'items'; else echo 'item' ?>">
                <td colspan="100">
                    <?php
                        if (is_array($item) && isset($item['template'])) {
                            $items = $item['items'];
                            include($base_path . $item['template']);
                        } else {
                            if($key == 'logo'){ $width = '250px'; }else{ $width = '860px';}
                    ?>
                        <img onerror="imgerror(this)" src="<?php echo $item['pic'] ?>" link="<?php echo $item['link'] ?>" style="max-width:100px;">
                    <?php
                        }
                    ?>
                </td>
            </tr>
        <?php
            }
        ?>

        <tfoor>
            <tr>
                <td colspan="100">
                    <a href="javascript:;" class="btn save_json">保存设置</a>
                </td>
            </tr>
        </tfoor>

    </table>

    <div class="layer_model" style="display: none;">
        <div style="padding: 20px;">

            <div style="width: 200px;float:left;">
                <h3> 点击图片上传：</h3>

                <p>
                    <input type="file" class="change_image" style="display: none;">
                    <img class="change_image" src="" alt="" style="max-width : 100px">
                </p>

                <h3> 链接：</h3>
                <p> <input type="url" class="txt-link w150"> </p>

                <h3> 名称： </h3>
                <p> <input type="text" class="txt-name w150"> </p>

                <h3> 价格： </h3>
                <p> <input type="text" class="txt-price w150"> </p>

                <h3> 简要描述： </h3>
                <p> <input type="text" class="txt-des w150"> </p>

                <p style="padding-top: 20px;">
                    <a href="javascript:;" class="btn save_img_link">保存</a>
                </p>

            </div>

            <div class="dialog-show-box" style="width:390px;float:right;">
                <table class="tb-type1 noborder search">
                    <tbody>
                    <tr>
                        <th><label>选择分类</label></th>
                        <td class="dialog-select-bar" id="recommend_gcategory">
                            <input type="hidden" id="cate_id" name="cate_id" value="0" class="mls_id">
                            <input type="hidden" id="cate_name" name="cate_name" value="" class="mls_names">
                            <select>
                                <option value="-1">请选择...</option>
                                <?php if(!empty($goods_class) && is_array($goods_class)) { ?>
                                    <?php foreach($goods_class as $k => $v) { ?>
                                        <option value="<?php echo $v['gc_id'];?>"><?php echo $v['gc_name'];?></option>
                                    <?php } ?>
                                <?php } ?>
                            </select>
                        </td>
                    </tr>
                    <script>
                        gcategoryInit('recommend_gcategory');
                    </script>
                    <tr>
                        <th><label for="goods_name">商品名称</label></th>
                        <td>
                            <input type="text" name="222goods_name" id="222goods_name">
                            <a href="javascript:"  class="btn-search " title="查询"></a>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <div id="show_recommend_goods_list">
                    <div class="dialog-goodslist-s2"></div>
                    <div id="show_recommend_goods" class="pagination"></div>
                </div>
                <script>

                    $(document).on('click','.pagination li a',function(){

                        var ttis = $(this);
                        var target_hrf = ttis.attr('href_');
                        var _body  = $(this).parents('.layui-layer-content');
                        var gc_id = 0;
                        $('#recommend_gcategory > select').each(function() {
                            if ($(this).val()>0) gc_id = $(this).val();
                        });
                        var goods_name = $(this).siblings('input').val();

                        $.ajax({
                            type:  'GET',
                            url:   target_hrf,
                            dataType: 'json',
                            success: function(data){
                                console.log(target_hrf);
                                var img_list = '';
                                $.each(data.goods_list,function(){
                                    img_list += '<li><div class="goods-pic" goods_name="'+this.goods_name+'" goods_img="'+this.goods_image+'" goods_id="'+this.goods_id+'" goods_des="'+this.goods_jingle+'" price="'+this.goods_price+'"><span class="thumb size-72x72"><img src="'+this.goods_image+'" height="72" width="72" /></span></div><div class="goods-name">"'+this.goods_name+'"</div></li>';
                                })
                                _body.find('#show_recommend_goods_list .dialog-goodslist-s2').html(img_list);
                                _body.find("#show_recommend_goods").html(data.page);
                                _body.find("#show_recommend_goods a").each(function(){
                                    var href_ = $(this).attr('href');
                                    $(this).attr('href_',href_);
                                    $(this).removeAttr('href');
                                })
                            }
                        })
                    });
                    $(document).on('click','#show_recommend_goods_list .goods-pic',function(){
                        var g_src = $(this).attr('goods_img');
                        var g_name = $(this).attr('goods_name');
                        var g_link = '/shop/index.php?act=goods&op=index&goods_id='+$(this).attr('goods_id');
                        var g_des = $(this).attr('goods_des');
                        var g_price = $(this).attr('price');
                        var _body  = $(this).parents('.layui-layer-content');
                        _body.find('img.change_image').eq(0).attr('src',g_src);
                        _body.find('input.txt-link').val(g_link);
                        _body.find('input.txt-name').val(g_name);
                        _body.find('input.txt-des').val(g_des);
                        _body.find('input.txt-price').val(g_price);
                    })
                </script>
                <div class="clear"></div>
            </div>
        </div>
    </div>
</div>